package com.ekuaitu.kuaitustaff.utils.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ekuaitu.kuaitustaff.R;

import java.util.List;


public class DialogCommentButton extends Dialog {

    private TextView tv_right;//确定按钮
    private TextView tv_left;//取消按钮
    private TextView titleTv;//消息标题文本
    private TextView messageTv;//消息提示文本
    private String messageStr;//从外界设置的消息文本
    private String titleStr;
    //确定文本和取消文本的显示内容
    private String leftStr, rightStr;
    private DialogCommentButton.onNoOnclickListener noOnclickListener;//取消按钮被点击了的监听器
    private DialogCommentButton.onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器
    private DialogCommentButton.onPictureClickListener picOnclickListener;//图片被点击了的监听器
    public ImageView ivComment;
    private TextView tvComment;
    private List<String> picList;

    /**
     * 设置取消按钮的显示内容和监听
     *
     * @param str
     * @param onNoOnclickListener
     */
    public void setNoOnclickListener(String str, DialogCommentButton.onNoOnclickListener onNoOnclickListener) {
        if (str != null) {
            leftStr = str;
        }
        this.noOnclickListener = onNoOnclickListener;
    }

    /**
     * 设置确定按钮的显示内容和监听
     *
     * @param str
     * @param onYesOnclickListener
     */
    public void setYesOnclickListener(String str, DialogCommentButton.onYesOnclickListener onYesOnclickListener) {
        if (str != null) {
            rightStr = str;
        }
        this.yesOnclickListener = onYesOnclickListener;
    }

    /**
     * 设置确定按钮的显示内容和监听
     *
     * @param picOnclickListener
     */
    public void setPicOnclickListener(DialogCommentButton.onPictureClickListener picOnclickListener) {
        this.picOnclickListener = picOnclickListener;
    }

    public DialogCommentButton(Context context, List<String> picList) {
        super(context, R.style.MyDialog);
        this.picList = picList;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_layout_comment);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();

    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        //设置确定按钮被点击后，向外界提供监听
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (yesOnclickListener != null) {
                    yesOnclickListener.onYesClick();
                }
            }
        });
        //设置取消按钮被点击后，向外界提供监听
        tv_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noOnclickListener != null) {
                    noOnclickListener.onNoClick();
                }
            }
        });
        ivComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (picOnclickListener != null) {
                    picOnclickListener.onPictureClick();
                }
            }
        });
    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData() {

    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        tv_left = (TextView) findViewById(R.id.tv_left);
        tv_right = (TextView) findViewById(R.id.tv_right);
        messageTv = (TextView) findViewById(R.id.tv_message);
        titleTv = (TextView) findViewById(R.id.tv_title);
        ivComment = findViewById(R.id.iv_notice);
        tvComment = findViewById(R.id.iv_notice_tv);
        //如果设置按钮的文字
        if (rightStr != null) {
            tv_right.setText(rightStr);
        }
        if (leftStr != null) {
            tv_left.setText(leftStr);
        }
        if (messageStr != null) {
            messageTv.setText(messageStr);
        }
        if (titleStr != null) {
            titleTv.setText(titleStr);
        }
        if (picList != null && picList.size() != 0) {
            ivComment.setVisibility(View.VISIBLE);
            //ImageLoader.getInstance().displayRoundImage(getContext(), MyApplication.imageUrl + picList.get(0), ivComment, 5);
        } else {
            ivComment.setVisibility(View.GONE);
        }
    }

    /**
     * dialog的message
     */
    public void setMessage(String message) {
        messageStr = message;
    }

    /**
     * dialog的title
     */
    public void setTitle(String title) {
        titleStr = title;
    }

    /**
     * 设置确定按钮和取消被点击的接口
     */
    public interface onYesOnclickListener {
        public void onYesClick();
    }

    public interface onNoOnclickListener {
        public void onNoClick();
    }

    public interface onPictureClickListener {
        public void onPictureClick();
    }

}
